home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / MacApp Release 10 / MacApp Release 10 - HD Ready / Libraries / Views / Sources / UPopup.cp < prev    next >
Encoding:
Text File  |  1996-04-03  |  20.4 KB  |  663 lines  |  [TEXT/MPS ]

  1. //----------------------------------------------------------------------------------------
  2. // UPopup.cp
  3. // Copyright © 1988-96 by Apple Computer, Inc. All rights reserved.
  4. //----------------------------------------------------------------------------------------
  5.  
  6. #ifndef __UPOPUP__
  7. #include "UPopup.h"
  8. #endif
  9.  
  10. // MacApp
  11.  
  12. #ifndef __UFAILURE__
  13. #include "UFailure.h"
  14. #endif
  15.  
  16. #ifndef __UGEOMETRY__
  17. #include "UGeometry.h"
  18. #endif
  19.  
  20. #ifndef __UMACAPPGLOBALS__
  21. #include "UMacAppGlobals.h"
  22. #endif
  23.  
  24. #ifndef __UMACAPPUTILITIES__
  25. #include "UMacAppUtilities.h"
  26. #endif
  27.  
  28. #ifndef __UMENUMGR__
  29. #include "UMenuMgr.h"
  30. #endif
  31.  
  32. #ifndef __USTREAM__
  33. #include "UStream.h"
  34. #endif
  35.  
  36. #ifndef __UWINDOW__
  37. #include "UWindow.h"
  38. #endif
  39.  
  40. // Toolbox
  41.  
  42. #ifndef __CONTROLS__
  43. #include <Controls.h>
  44. #endif
  45.  
  46. #ifndef __ERRORS__
  47. #include <Errors.h>
  48. #endif
  49.  
  50. #ifndef __RESOURCES__
  51. #include <Resources.h>
  52. #endif
  53.  
  54. #ifndef __TOOLUTILS__
  55. #include <ToolUtils.h>
  56. #endif
  57.  
  58. // ANSI
  59.  
  60. #ifndef __STDIO__
  61. #include <stdio.h>
  62. #endif
  63.  
  64. //----------------------------------------------------------------------------------------
  65. const short kMAPopupRsrcID = 128;                // The rsrc id of the Popup CDEF supplied
  66.                                                 // with MacApp.
  67.  
  68. //----------------------------------------------------------------------------------------
  69.  
  70. // The following data structure is a private data structure used by the popup CDEF. It
  71. // lives as a privHdl off the control handle's contrlData field. The first two fields of
  72. // the private data structure are "public" but the rest are private.
  73. typedef struct 
  74. {
  75.     MenuRef mHandle;                            // the popup's menu handle 
  76.     short mID;                                    // the popup's menu id 
  77.     short mLastMenuID;                            // last menu id selected (System 7 only)
  78.     short mLastItem;                            // last item selected (System 7 only)
  79.     SignedByte* mPrivate;
  80. } popupPrivateData, *popupPrivateDataPtr, **popupPrivateDataHandle;
  81.  
  82.  
  83. //========================================================================================
  84. // CLASS TPopup
  85. //========================================================================================
  86. #undef Inherited
  87. #define Inherited TCtlMgr
  88.  
  89. #pragma segment DlgOpen
  90. MA_DEFINE_CLASS_M1(TPopup, Inherited);
  91.  
  92. //----------------------------------------------------------------------------------------
  93. // TPopup constructor
  94. //----------------------------------------------------------------------------------------
  95. #pragma segment DlgOpen
  96.  
  97. TPopup::TPopup()
  98. {
  99.     fEventNumber = mPopupHit;
  100.  
  101.     fItemOffset = 0; 
  102.     fTitleStyle = popupTitleNoStyle;
  103.     fTitleJust = popupTitleLeftJust;
  104.     fUseAddResMenu = FALSE;
  105.     fUseAddResMenuResType = kNoIdentifier;
  106.     fUseAddResMenuNumberInitialItems = 0;
  107.     fStrListID = kNoResource;                        // popup's title:    STR# rsrc id
  108.     fIndex = kNoResource;                            //                    index into STR#
  109.     fMacAppSetDimState = FALSE;
  110.  
  111. } // TPopup::TPopup
  112.  
  113. //----------------------------------------------------------------------------------------
  114. // TPopup::Free: 
  115. //----------------------------------------------------------------------------------------
  116. #pragma segment DlgClose
  117.  
  118. TPopup::~TPopup()
  119. {
  120.     if (fUseAddResMenu) {
  121.         MenuRef theMenuRef = this->GetMenuRef();
  122.         
  123.         if (theMenuRef != NULL) {
  124.             for (short i = CountMItems(theMenuRef); i > fUseAddResMenuNumberInitialItems; i--)
  125.                 DeleteMenuItem(theMenuRef, i);
  126.         }
  127.     }
  128. }
  129.  
  130. //----------------------------------------------------------------------------------------
  131. // TPopup::IPopup: 
  132. //----------------------------------------------------------------------------------------
  133. #pragma segment DlgOpen
  134.  
  135. void TPopup::IPopup(TView* itsSuperView,
  136.                            const VPoint& itsLocation,
  137.                            const VPoint& itsSize,
  138.                            SizeDeterminer itsHSizeDet,
  139.                            SizeDeterminer itsVSizeDet,
  140.                            short itsMenuID,                // rsrc ID of 'MENU' or 'CMNU' rsrc 
  141.                            short itsCurrentItem,
  142.                            short itsItemOffset,            // width of the popup title area 
  143.                            short itsStrListID,            // popup's title:    STR# rsrc id
  144.                            short itsIndex,                //                    index into STR#
  145.                            /* Style */ short itsStyle,    // title's style 
  146.                            short itsJust,                // title's justification 
  147.                            Boolean useAddResMenu,        // true if want to AppendResMenu (can use
  148.                                                         // this option iff menuID != kNoResource)
  149.                            ResType useAddResMenuResType,// used if useAddResMenu is true
  150.                            const TextStyle& itsTextStyle)
  151.  
  152. {
  153.     fUseAddResMenu = useAddResMenu;
  154.     fUseAddResMenuResType = useAddResMenuResType;
  155.  
  156.     // initialize the popup
  157.     CStr255 itsLabel;
  158.     if (itsStrListID != kNoResource)
  159.         GetIndString(itsLabel, itsStrListID, itsIndex);
  160.     fTitleStyle = itsStyle;
  161.     fTitleJust = itsJust;
  162.     fSizeDeterminer[hSel] = itsHSizeDet;            // needed for call to this->GetProcID()
  163.  
  164.     // set up the rest of the instance variables 
  165.     fMenuID = itsMenuID;
  166.     fItemOffset = itsItemOffset;
  167.  
  168.     ICtlMgr(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsLabel, itsCurrentItem,
  169.             0, 0, 0, itsTextStyle);
  170. } // TPopup::IPopup 
  171.  
  172. //----------------------------------------------------------------------------------------
  173. // TPopup::GetPopupTitleStyle: 
  174. //----------------------------------------------------------------------------------------
  175. #pragma segment DlgOpen
  176.  
  177. unsigned short TPopup::GetPopupTitleStyle()
  178. {
  179.     unsigned short popupTitleStyle;
  180.  
  181.     // set up justification value
  182.     if (fTitleJust == teJustCenter)
  183.         popupTitleStyle = popupTitleCenterJust;
  184.     else if (fTitleJust == teJustRight)
  185.         popupTitleStyle = popupTitleRightJust;
  186.     else
  187.         popupTitleStyle = popupTitleLeftJust;        // default value: note sets high-bit of lo-word
  188.  
  189.     // set up style value
  190.     if (fTitleStyle == normal)
  191.         popupTitleStyle += popupTitleNoStyle;
  192.     else
  193.     {
  194.         if (macroIn(fTitleStyle, bold))
  195.             popupTitleStyle += popupTitleBold;
  196.         if (macroIn(fTitleStyle, italic))
  197.             popupTitleStyle += popupTitleItalic;
  198.         if (macroIn(fTitleStyle, underline))
  199.             popupTitleStyle += popupTitleUnderline;
  200.         if (macroIn(fTitleStyle, outline))
  201.             popupTitleStyle += popupTitleOutline;
  202.         if (macroIn(fTitleStyle, shadow))
  203.             popupTitleStyle += popupTitleShadow;
  204.         if (macroIn(fTitleStyle, condense))
  205.             popupTitleStyle += popupTitleCondense;
  206.         if (macroIn(fTitleStyle, extend))
  207.             popupTitleStyle += popupTitleExtend;
  208.     }
  209.  
  210.     return popupTitleStyle;
  211. } // TPopup::GetPopupTitleStyle 
  212.  
  213. //----------------------------------------------------------------------------------------
  214. // TPopup::GetProcID: 
  215. //----------------------------------------------------------------------------------------
  216. #pragma segment DlgOpen
  217.  
  218. short TPopup::GetProcID()
  219. {
  220.     short    itsProcID = popupMenuProc;
  221.  
  222.     itsProcID += popupUseWFont;                        // always use window font
  223.  
  224.     if (fUseAddResMenu)
  225.         itsProcID += popupUseAddResMenu;            // set if popup uses AppendResMenu 
  226.  
  227.     if (fSizeDeterminer[hSel] == sizeFixed)
  228.         itsProcID += popupFixedWidth;                // set if popup has fixed width 
  229.  
  230.     return itsProcID;
  231. } // TPopup::GetProcID 
  232.  
  233. //----------------------------------------------------------------------------------------
  234. // TPopup::CreateCMgrControl: 
  235. //----------------------------------------------------------------------------------------
  236. #pragma segment DlgOpen
  237.  
  238. void TPopup::CreateCMgrControl(const CStr255& itsTitle,
  239.                                       long itsVal,
  240.                                       long /* itsMin */,
  241.                                       long /* itsMax */,
  242.                                       short /* itsProcID */)// override 
  243. {
  244.     short    numInitialItemsInMenu = 0;        // used if we are using AppendResMenu
  245.     
  246.     // NOTE: we ignore the values passed in for itsMin, itsMax,  and itsProcID since the
  247.     // popup CDEF defines these values differently for the NewControl call. So compute instead...
  248.  
  249.     // look 'n see if it's in the menubar
  250.     MenuRef itsMenu = ::GetMenuHandle(this->GetMenuID());
  251.     if (itsMenu == NULL)
  252.     {    // nope, it's not in the menubar...insert it
  253.         itsMenu = this->GetMenuRef();
  254.         if (itsMenu)
  255.             InsertMenu(itsMenu, hierMenu);                        // stick it in
  256.         else
  257.         {
  258. #if qDebug
  259.             fprintf(stderr, "TPopup::CreateCMgrControl needs menu id for a MENU or CMNU.\n");
  260.             Failure(resNotFound, 0);
  261. #endif
  262.         }
  263.     }
  264.     
  265.     if (fUseAddResMenu)
  266.         numInitialItemsInMenu = this->GetNumberOfItems();
  267.  
  268.     TWindow* itsTWindow = this->GetWindow();
  269.     WindowRef itsWindow = itsTWindow ? itsTWindow->fWMgrWindow : gWorkPort;
  270.  
  271.     // set the port appropriately
  272.     GrafPtr savePort;
  273.     GetPort(&savePort);
  274.     SetPortWindowPort(itsWindow);
  275.  
  276.     // Set up the port's text style -- NewControl needs this.
  277.     TextStyle aTextStyle = fTextStyle;
  278.     SetPortTextStyle(aTextStyle);
  279.     PenNormal();
  280.     
  281.     // create the control
  282.     ControlRef aCMgrControl = NewControl(itsWindow, &this->ControlQDArea(), itsTitle, FALSE,
  283.                                          (short)this->GetPopupTitleStyle(), fMenuID, fItemOffset,
  284.                                          this->GetProcID(), fUseAddResMenuResType);
  285.     SetPort(savePort);                                // restore port before signalling failure
  286.     FailNIL(aCMgrControl);
  287.  
  288.     // Need to signal failure if the CDEF's private storage couldn't be created -- this is
  289.     // most likely due to a missing MENU or CMNU resource with fMenuID.
  290.     FailNIL((*aCMgrControl)->contrlData);
  291.  
  292.     SetControlReference(aCMgrControl, (long)this);    // Set refCon here, it has a special value at
  293.                                                     // NewControl time - the ResType for the case
  294.                                                     // in which the popup's variation code has
  295.                                                     // popupUseAddResMenu.
  296.  
  297.     fCMgrControl = aCMgrControl;
  298.     this->DimState(fDimmed, kDontRedraw);
  299.     
  300.     // Remember, the control was created with "magic" values, fix it up.
  301.     this->SetLongValues(itsVal, 1, this->GetNumberOfItems(), kDontRedraw);
  302.  
  303.     this->SetCMgrVisibility(itsWindow != gWorkPort);
  304.     
  305.     if (fUseAddResMenu)
  306.         fUseAddResMenuNumberInitialItems = numInitialItemsInMenu;
  307. } // TPopup::CreateCMgrControl 
  308.  
  309. //----------------------------------------------------------------------------------------
  310. // TPopup::GetStandardSignature: 
  311. //----------------------------------------------------------------------------------------
  312. #pragma segment DlgWriteResource
  313.  
  314. IDType TPopup::GetStandardSignature()    // override 
  315. {
  316.     return kStdPopup;
  317. } // TPopup::GetStandardSignature 
  318.  
  319. //----------------------------------------------------------------------------------------
  320. // TPopup::ReadFields: 
  321. //----------------------------------------------------------------------------------------
  322. #pragma segment DlgReadResource
  323.  
  324. void TPopup::ReadFields(TStream* aStream)                // override 
  325. {
  326.     Inherited::ReadFields(aStream);
  327.     
  328.     FailInfo fi;
  329.     Try(fi)
  330.     {
  331.         fMenuID = aStream->ReadInteger();
  332.         short itsCurrentItem = aStream->ReadInteger();
  333.         fItemOffset = aStream->ReadInteger();
  334.     
  335.         fTitleStyle = (Style)aStream->ReadByte();
  336.         fTitleJust = aStream->ReadInteger();
  337.         fUseAddResMenu = aStream->ReadBoolean();
  338.         fUseAddResMenuResType = aStream->ReadLong();
  339.         fStrListID = aStream->ReadInteger();
  340.         fIndex = aStream->ReadInteger();
  341.     
  342.         CStr255    itsLabel;
  343.         this->GetMenuLabel(itsLabel);
  344.     
  345.         // initialize the popup 
  346.         this->CreateCMgrControl(itsLabel, itsCurrentItem, 0, 0, 0);
  347.         fi.Success();
  348.     }
  349.     else
  350.     {
  351.         this->Free();
  352.         fi.ReSignal();
  353.     }
  354. } // TPopup::ReadFields 
  355.  
  356. //----------------------------------------------------------------------------------------
  357. // TPopup::WriteFields: 
  358. //----------------------------------------------------------------------------------------
  359. #pragma segment DlgWriteResource
  360.  
  361. void TPopup::WriteFields(TStream* aStream)        // override 
  362. {
  363.     Inherited::WriteFields(aStream);
  364.  
  365.     aStream->WriteInteger(this->GetMenuID());
  366.     aStream->WriteInteger(this->GetCurrentItem());
  367.     aStream->WriteInteger(fItemOffset);
  368.  
  369.     aStream->WriteByte(fTitleStyle);
  370.     aStream->WriteInteger(fTitleJust);
  371.     aStream->WriteBoolean(fUseAddResMenu);
  372.     aStream->WriteLong(fUseAddResMenuResType);
  373.     aStream->WriteInteger(fStrListID);
  374.     aStream->WriteInteger(fIndex);
  375. } // TPopup::WriteFields 
  376.  
  377. //----------------------------------------------------------------------------------------
  378. // TView::Focus: 
  379. //----------------------------------------------------------------------------------------
  380. #pragma segment MAViewRes
  381.  
  382. Boolean TPopup::Focus()
  383. {
  384.     // To Focus, must be able to focus, and be drawable, so as to avoid a bug in the
  385.     // CDEF/MDEF in which a bus error results when drawing if the popup isn't
  386.     // drawable (e.g. if it's off-screen).
  387.     return Inherited::Focus() && !((CRect&)(*GetClipRegion(qd.thePort))->rgnBBox).Empty();
  388. } // TView::Focus 
  389.  
  390. //----------------------------------------------------------------------------------------
  391. // TPopup::Draw: 
  392. //----------------------------------------------------------------------------------------
  393. #pragma segment DlgRes
  394.  
  395. void TPopup::Draw(const VRect& area)        // override 
  396. {
  397.     // may need to set the lo memory globals for the font/size since the CDEF will
  398.     // occasionally ignore the values
  399.  
  400.     if (this->GetNumberOfItems() == 0)
  401.     {
  402.         fMacAppSetDimState = TRUE;
  403.         this->DimState(TRUE, kDontRedraw); //no items, Dim Popup
  404.     }
  405.     else if (fDimmed && fMacAppSetDimState)
  406.     {
  407.         fMacAppSetDimState = FALSE;
  408.          this->DimState(FALSE,kDontRedraw); 
  409.      }
  410.         
  411.     Inherited::Draw(area);
  412. } // TPopup::Draw 
  413.  
  414. //----------------------------------------------------------------------------------------
  415. // TPopup::DoMouseCommand: 
  416. //----------------------------------------------------------------------------------------
  417. #pragma segment DlgRes
  418.  
  419. void TPopup::DoMouseCommand(VPoint& theMouse,
  420.                                    TToolboxEvent* event,
  421.                                    CPoint hysteresis)// override 
  422. {
  423.     if (!this->Focus())                            // set up the font/size
  424.     {
  425.         TextStyle aTextStyle = fTextStyle;
  426.         SetPortTextStyle(aTextStyle);
  427.     }
  428.  
  429.     Inherited::DoMouseCommand(theMouse, event, hysteresis);
  430. } // TPopup::DoMouseCommand 
  431.  
  432. //----------------------------------------------------------------------------------------
  433. // TPopup::AttachMenuRef: 
  434. //----------------------------------------------------------------------------------------
  435. #pragma segment DlgRes
  436.  
  437. void TPopup::AttachMenuRef(MenuRef itsMenuRef)
  438. {
  439.     MenuRef currentMenuRef;
  440.  
  441.     // first, a quick safety check to make sure that we do nothing if we are trying to
  442.     // install a menu that is already installed
  443.     currentMenuRef = this->GetMenuRef();
  444.     if (currentMenuRef != itsMenuRef)
  445.     {
  446.         if (currentMenuRef)                    // first, release the old MenuRef 
  447.         {
  448.             // There are 3 cases that we need to account for here:
  449.             //    1. if fMenuRef is a converted 'CMNU' resource    => leave MenuRef alone;
  450.             //    2. if fMenuRef is a 'MENU' resource                 => call ReleaseResource;
  451.             //    3. if fMenuRef is a menu created with NewMenu    => call DisposeMenu.
  452.             // N.B.: you should never call GetMenu to create the MenuRef, instead call MAGetMenu.
  453.             if (IsManagedMenu(currentMenuRef))// case 1
  454.                 ;                                // do nothing
  455.             else if (IsAResource((Handle)currentMenuRef))// case 2 
  456.                 ReleaseResource((Handle)currentMenuRef);
  457.             else                                // case 3 
  458.                 DisposeMenu(currentMenuRef);
  459.             currentMenuRef = NULL;
  460.             this->SetCMgrVisibility(FALSE);
  461.             SizeControl(fCMgrControl, 0, 0);
  462.             DisposeControl(fCMgrControl);
  463.             fCMgrControl = NULL;
  464.         }
  465.  
  466.         // set the menu handle in  the popup's private storage 
  467.         if (itsMenuRef)
  468.         {
  469.             fMenuID = (*itsMenuRef)->menuID;
  470.             CStr255 itsTitle;
  471.             this->GetMenuLabel (itsTitle);
  472.             this->CreateCMgrControl(itsTitle, 1 , 0, 0, 0);
  473.  
  474.             // set up the control's needed values 
  475.             this->SetLongValues(1, 1, this->GetNumberOfItems(), kDontRedraw);
  476.         }
  477.     }
  478. } // TPopup::AttachMenuRef 
  479.  
  480. //----------------------------------------------------------------------------------------
  481. // TPopup::GetMenuRef: 
  482. //----------------------------------------------------------------------------------------
  483. #pragma segment DlgRes
  484.  
  485. MenuRef TPopup::GetMenuRef()
  486. {
  487.     return MAGetMenu(this->GetMenuID());
  488. } // TPopup::GetMenuRef 
  489.  
  490. //----------------------------------------------------------------------------------------
  491. // TPopup::GetMenuLabel: 
  492. //----------------------------------------------------------------------------------------
  493. #pragma segment DlgRes
  494.  
  495. void TPopup::GetMenuLabel(CStr255& itsLabel)
  496. {
  497.     if (fStrListID != kNoResource)                    // retrieve the menu label from the resource
  498.         GetIndString(itsLabel, fStrListID, fIndex);
  499.     else
  500.     {
  501.         MenuRef itsMenuRef;                    // retrieve the menu label from the menu
  502.         if ((itsMenuRef = this->GetMenuRef()) != NULL)
  503.             GetMenuItemText(itsMenuRef, 0, itsLabel);
  504.         else
  505.             itsLabel.Empty();
  506.     }    
  507. } // TPopup::GetMenuLabel 
  508.  
  509. //----------------------------------------------------------------------------------------
  510. // TPopup::GetCurrentCommand: 
  511. //----------------------------------------------------------------------------------------
  512. #pragma segment DlgRes
  513.  
  514. CommandNumber TPopup::GetCurrentCommand()
  515. {
  516.     return CommandFromMenuItem(this->GetLastMenuID(), this->GetLastItem());
  517. } // TPopup::GetCurrentCommand 
  518.  
  519. //----------------------------------------------------------------------------------------
  520. // TPopup::GetCurrentItem: 
  521. //----------------------------------------------------------------------------------------
  522. #pragma segment DlgRes
  523.  
  524. short TPopup::GetCurrentItem()
  525. {
  526.     return this->GetVal();
  527. } // TPopup::GetCurrentItem 
  528.  
  529. //----------------------------------------------------------------------------------------
  530. // TPopup::GetLastItem: 
  531. //----------------------------------------------------------------------------------------
  532. #pragma segment DlgRes
  533.  
  534. short TPopup::GetLastItem()
  535. {
  536. #if 0
  537.     // the following code is only supported for the System 7 CDEF
  538.     if (fCMgrControl)
  539.     {
  540.         short lastItem = GetControlMaximum(fCMgrControl);
  541.         
  542. //SRF        if ((lastItem = (*(popupPrivateDataHandle)(*fCMgrControl)->contrlData)->mLastItem) != 0)
  543.         if (lastItem)
  544.             return lastItem;
  545.     }
  546.     
  547. #endif
  548.     return this->GetCurrentItem();
  549. } // TPopup::GetLastItem 
  550.  
  551. //----------------------------------------------------------------------------------------
  552. // TPopup::GetMenuID: 
  553. //----------------------------------------------------------------------------------------
  554. #pragma segment DlgRes
  555.  
  556. short TPopup::GetMenuID()
  557. {
  558.     return fMenuID;
  559. } // TPopup::GetMenuID 
  560.  
  561. //----------------------------------------------------------------------------------------
  562. // TPopup::GetLastMenuID: 
  563. //----------------------------------------------------------------------------------------
  564. #pragma segment DlgRes
  565.  
  566. short TPopup::GetLastMenuID()
  567. {
  568. #if 0
  569.     // the following code is only supported for the System 7 CDEF
  570.     if (fCMgrControl)
  571.     {
  572.         short lastMenuID = (*(popupPrivateDataHandle)(*fCMgrControl)->contrlData)->mLastMenuID);
  573.  
  574. //SRF        if ((lastMenuID = (*(popupPrivateDataHandle)(*fCMgrControl)->contrlData)->mLastMenuID) != 0)
  575.         if (lastMenuID)
  576.             return lastMenuID;
  577.     }
  578.  
  579. #endif
  580.     return this->GetMenuID();                        // default if no last result
  581. } // TPopup::GetLastMenuID 
  582.  
  583. //----------------------------------------------------------------------------------------
  584. // TPopup::GetItemText: 
  585. //----------------------------------------------------------------------------------------
  586. #pragma segment DlgRes
  587.  
  588. void TPopup::GetItemText(short item,
  589.                                 CStr255& theText)
  590. {
  591.     MenuRef itsMenuRef;
  592.  
  593.     if ((itsMenuRef = this->GetMenuRef()) != NULL)
  594.         GetMenuItemText(itsMenuRef, item, theText);
  595.     else
  596.         theText.Empty();
  597. } // TPopup::GetItemText 
  598.  
  599. //----------------------------------------------------------------------------------------
  600. // TPopup::GetNumberOfItems: 
  601. //----------------------------------------------------------------------------------------
  602. #pragma segment DlgRes
  603.  
  604. short TPopup::GetNumberOfItems()
  605. {
  606.     MenuRef itsMenuRef;
  607.     if ((itsMenuRef = this->GetMenuRef()) != NULL)
  608.         return CountMItems(itsMenuRef);                // if possible, query the menu
  609.     else
  610.         return this->GetMax();                            // else query the control
  611. } // TPopup::GetNumberOfItems 
  612.  
  613. //----------------------------------------------------------------------------------------
  614. // TPopup::GetTitle: 
  615. //----------------------------------------------------------------------------------------
  616. #pragma segment DlgRes
  617.  
  618. void TPopup::GetTitle(CStr255& title)
  619. {
  620.     this->GetText(title);
  621. } // TPopup::GetTitle 
  622.  
  623. //----------------------------------------------------------------------------------------
  624. // TPopup::SetCurrentItem: 
  625. //----------------------------------------------------------------------------------------
  626. #pragma segment DlgRes
  627.  
  628. void TPopup::SetCurrentItem(short item,
  629.                                    Boolean redraw)
  630. {
  631.     this->SetLongVal(item, redraw);
  632. } // TPopup::SetCurrentItem 
  633.  
  634. //----------------------------------------------------------------------------------------
  635. // TPopup::SetPopup: 
  636. //----------------------------------------------------------------------------------------
  637. #pragma segment DlgRes
  638.  
  639. void TPopup::SetPopup(MenuRef itsMenuRef,
  640.                                       short itsCurrentItem,
  641.                                       Boolean redraw)
  642. {
  643.     this->AttachMenuRef(itsMenuRef);
  644.     this->SetCurrentItem(itsCurrentItem, redraw);
  645.     if (redraw)
  646.         this->ForceRedraw();
  647. } // TPopup::SetPopup 
  648.  
  649. //----------------------------------------------------------------------------------------
  650. // TPopup::SetTitle: 
  651. //----------------------------------------------------------------------------------------
  652. #pragma segment DlgRes
  653.  
  654. void TPopup::SetTitle(const CStr255& title)
  655. {
  656.     this->SetText(title, kDontRedraw);
  657. } // TPopup::SetTitle 
  658.  
  659. //----------------------------------------------------------------------------------------
  660. // End of UPopup.cp
  661.  
  662. #pragma segment Inline
  663.